<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // function play(playerList, num) {
        //     const queue = new Queue();
        //     for (let i = 0; i < playerList.length; i++) {
        //         queue.enqueue(playerList[i]);

        //     }
        //     while (queue.size() > 1) {
        //         for (let i = 0; i < num - 1; i++) {
        //             queue.enqueue(queue.dequeue());
        //         }
        //         let out = queue.dequeue();
        //         console.log("淘汰+out");
        //     }
        // }
        class Deque {
            constructor() {
                this.item = [];
            }
            addFront(element) {
                this.item.unshift(element);
            }
            addBack(element) {
                this.item.push(element);
            }
            removeFront() {
                return this.item.push()
            }
            removeBack() {
                return this.item.pop();
            }
            toString() {
                return this.item.toString();
            }
            peekFront() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[0];
                }
            }
            peekBack() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[this.item.length - 1];
                }
            }
        }
        const deque = new Deque();
        deque.addBack("abcd");
        deque.addBack("abc");
        deque.addFront("abcde")
        console.log(deque.toString());
        console.log("打印所有" + deque.toString());
        console.log("前一" + deque.peekFront());
        console.log("后一" + deque.peekBack());
    </script>
</body>

</html>